/**
 * getDerivedStateFromProps
 */
import React, { Component } from 'react'

export default class App extends Component {
    state = {
        name: "张无忌"
    }
    static getDerivedStateFromProps(nextProps, nextState) {
        console.log("getDerivedStateFromProps");
        return {
            name: nextState.name.replace("张", "李")
        }
    }
    render() {
        return (
            <div>
                <button onClick={() => {
                    this.setState({ name: "周芷若" })
                }}>Click</button>
                Derive-{this.state.name}
            </div>
        )
    }
}
